/**
 * 
 */
package coop.tecso.core.test.handlers;

import org.org.usurper.handlers.basic.AbstractPropertyTypeHandler;
import org.org.usurper.handlers.basic.AbstractSpecificPropertyHandler;
import org.org.usurper.model.HandledBeanProperty;
import org.org.usurper.model.HandledConstructorArg;

/**
 * @author daniel
 *
 */
public class PropertySingletonHandler extends AbstractPropertyTypeHandler {

    private AbstractPropertyTypeHandler handler;
    private Object handled;
    
    /**
     * 
     */
    public PropertySingletonHandler(AbstractPropertyTypeHandler handler) {
        super(handler.getHandledTypes());
        this.handler = handler;
    }
    
    /* (non-Javadoc)
     * @see org.org.usurper.handlers.IHandler#handle(org.org.usurper.model.HandledBeanProperty)
     */
    @Override
    public Object handle(HandledBeanProperty handledBeanProperty) {
        if(handled == null){
            handled = handler.handle(handledBeanProperty);
        }
        return handled;
    }

    /* (non-Javadoc)
     * @see org.org.usurper.handlers.IHandler#handle(org.org.usurper.model.HandledConstructorArg)
     */
    @Override
    public Object handle(HandledConstructorArg handledConstructorArg) {
        if(handled == null){
            handled = handler.handle(handledConstructorArg);
        }
        return handled;
    }

}
